<!-- build time:Tue Dec 17 2019 19:26:48 GMT+0800 (GMT+08:00) --><!doctype html><html class="theme-next mist" lang="zh-Hans"><head><meta name="generator" content="Hexo 3.8.0"><meta name="google-site-verification" content="7Tau9WyVgxnsEY9oYedu9g0U6_8akOX3wiKbaYcrg9A"><meta name="baidu-site-verification" content="EVwLiaxdxX"><link href="/css/xps13.css" rel="stylesheet" type="text/css"><link href="/css/message.css" rel="stylesheet" type="text/css"><script type="text/javascript" src="/js/jquery-1.11.3.min.js"></script><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css"><link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css"><meta name="keywords" content="MyBatis,"><link rel="alternate" href="/atom.xml" title="MrBird" type="application/atom+xml"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1"><meta name="description" content="MyBatis中的级联分为3种：association，collection和discriminator：1.association：代表一对一关系，比如学生和学生证是一对一关系。2.collection：代表一对多关系，比如学生和课程是一对多关系，一个学生可以有多个课程。3.discriminator：鉴别器，它可以根据实际选择采用哪个类作为实例，允许你根据特定的条件去关联不同的结果集。为了学习"><meta name="keywords" content="MyBatis"><meta property="og:type" content="article"><meta property="og:title" content="MyBatis级联"><meta property="og:url" content="http://mrbird.cc/MyBatis级联.html"><meta property="og:site_name" content="MrBird"><meta property="og:description" content="MyBatis中的级联分为3种：association，collection和discriminator：1.association：代表一对一关系，比如学生和学生证是一对一关系。2.collection：代表一对多关系，比如学生和课程是一对多关系，一个学生可以有多个课程。3.discriminator：鉴别器，它可以根据实际选择采用哪个类作为实例，允许你根据特定的条件去关联不同的结果集。为了学习"><meta property="og:locale" content="zh-Hans"><meta property="og:image" content="http://mrbird.cc/img/89371248-file_1487995784939_c58d.png"><meta property="og:updated_time" content="2019-10-28T12:14:46.253Z"><meta name="twitter:card" content="summary"><meta name="twitter:title" content="MyBatis级联"><meta name="twitter:description" content="MyBatis中的级联分为3种：association，collection和discriminator：1.association：代表一对一关系，比如学生和学生证是一对一关系。2.collection：代表一对多关系，比如学生和课程是一对多关系，一个学生可以有多个课程。3.discriminator：鉴别器，它可以根据实际选择采用哪个类作为实例，允许你根据特定的条件去关联不同的结果集。为了学习"><meta name="twitter:image" content="http://mrbird.cc/img/89371248-file_1487995784939_c58d.png"><script type="text/javascript" id="hexo.configurations">var NexT=window.NexT||{},CONFIG={root:"/",scheme:"Mist",sidebar:{position:"left",display:"always",offset:12,offset_float:0,b2t:!1,scrollpercent:!1},fancybox:!1,motion:!1}</script><title>MyBatis级联 | MrBird</title></head><body ondragstart="return!1" class="animsition" lang="zh-Hans" style="overflow-x:hidden;padding-right:280px"><script type="text/javascript" src="/js/mo.min.js"></script><style>@media (min-width:768px) and (max-width:991px){body .header-innerr{width:700px!important}}.header-innerr{margin:0 auto;padding:100px 0 70px;width:880px}@media (min-width:1600px){.container .header-innerr{width:1200px}}.header-innerr{position:relative}.header-innerr{padding:20px 0 0}.header-innerr:after,.header-innerr:before{content:" ";display:table}.header-innerr:after{clear:both}@media (max-width:767px){.header-innerr{width:auto;padding:10px;margin-bottom:-20px}}</style><div class="container sidebar-position-left page-post-detail"><div class="headband"></div><header id="header" class="header"><div class="header-inner"><div class="site-brand-wrapper"><div class="site-meta"><link href="https://fonts.font.im/css?family=Merienda" rel="stylesheet"><div class="custom-logo-site-title"><a href="/" class="brand" rel="start"><span class="logo-line-before"><i></i></span> <span class="site-title" style="font-family:Merienda;font-size:1.3rem">MrBird</span> <span class="logo-line-after"><i></i></span></a></div><p class="site-subtitle"></p></div><div class="site-nav-toggle"><button><span class="btn-bar"></span> <span class="btn-bar"></span> <span class="btn-bar"></span></button></div></div><nav class="site-nav"><ul id="menu" class="menu"><li class="menu-item menu-item-home"><a href="/" rel="section">HOME</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section">ARCHIVES</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section">TAGS</a></li><li class="menu-item menu-item-friends"><a href="/friends/" rel="section">FRIENDS</a></li><div class="sidebar-toggle" style="display:none"><div class="sidebar-toggle-line-wrap"><span class="sidebar-toggle-line sidebar-toggle-line-first"></span> <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span> <span class="sidebar-toggle-line sidebar-toggle-line-last"></span></div></div></ul><div class="site-search"><div class="popup search-popup local-search-popup"><div class="local-search-header clearfix"><span class="search-icon"><i class="fa fa-search"></i> </span><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span><div class="local-search-input-wrapper"><input autocomplete="off" placeholder="Search" spellcheck="false" type="text" id="local-search-input"></div></div><div id="local-search-result"></div></div></div></nav></div><div class="header-innerr"><div class="note info" style="margin:0;letter-spacing:.15px">🐤手把手教你搭建<strong>Spring Cloud微服务权限系统</strong>（从零到部署）：<a style="color:#40dab2;font-weight:600" href="https://www.kancloud.cn/mrbird/spring-cloud" target="_blank">https://www.kancloud.cn/mrbird/spring-cloud</a></div></div></header><main id="main" class="main"><div class="main-inner"><div class="content-wrap"><div id="content" class="content"><div id="posts" class="posts-expand"><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><link itemprop="mainEntityOfPage" href="http://mrbird.cc/MyBatis级联.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content="MrBird"><meta itemprop="description" content=""><meta itemprop="image" content="/images/blogImage.jpg"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="MrBird"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">MyBatis级联</h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="fa fa-calendar-o"></i> </span><span class="post-meta-item-text">Posted on</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-05T10:38:12+08:00">2017-01-05 </time></span><span></span> <span class="post-meta-divider">|</span> <span class="page-pv"><i class="fa fa-laptop"></i>&nbsp;&nbsp;Visit count <span class="busuanzi-value" id="busuanzi_value_page_pv"></span></span></div></header><div class="post-body" itemprop="articleBody"><p>MyBatis中的级联分为3种：association，collection和discriminator：</p><p>1.<code>association</code>：代表一对一关系，比如学生和学生证是一对一关系。</p><p>2.<code>collection</code>：代表一对多关系，比如学生和课程是一对多关系，一个学生可以有多个课程。</p><p>3.<code>discriminator</code>：鉴别器，它可以根据实际选择采用哪个类作为实例，允许你根据特定的条件去关联不同的结果集。</p><p>为了学习这些东东，设计一个模型关系：<br><a id="more"></a></p><p><img src="img/89371248-file_1487995784939_c58d.png" alt="89371248-file_1487995784939_c58d.png"></p><p>根据模型新建库表：</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">CREATE</span> <span class="keyword">TABLE</span> t_lecture(</span><br><span class="line">    <span class="keyword">id</span> <span class="built_in">int</span>(<span class="number">20</span>) <span class="keyword">not</span> <span class="literal">null</span> auto_increment <span class="keyword">comment</span> <span class="string">'编号'</span>,</span><br><span class="line">    lecture_name <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">null</span> <span class="keyword">comment</span> <span class="string">'课程名称'</span>,</span><br><span class="line">    PRIMARY <span class="keyword">KEY</span> (<span class="keyword">id</span>)</span><br><span class="line">);</span><br><span class="line"> </span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">table</span> t_student(</span><br><span class="line">    <span class="keyword">id</span> <span class="built_in">int</span>(<span class="number">20</span>) <span class="keyword">not</span> <span class="literal">null</span> auto_increment <span class="keyword">comment</span> <span class="string">'编号'</span>,</span><br><span class="line">    cnname <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">null</span> <span class="keyword">comment</span> <span class="string">'学生姓名'</span>,</span><br><span class="line">    sex TINYINT(<span class="number">4</span>) <span class="keyword">not</span> <span class="literal">null</span> <span class="keyword">COMMENT</span> <span class="string">'性别'</span>,</span><br><span class="line">    selfcard_no <span class="built_in">int</span>(<span class="number">20</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'学生证号'</span>,</span><br><span class="line">    note <span class="built_in">VARCHAR</span>(<span class="number">1024</span>) <span class="keyword">COMMENT</span> <span class="string">'备注'</span>,</span><br><span class="line">    PRIMARY <span class="keyword">KEY</span> (<span class="keyword">id</span>)</span><br><span class="line">);</span><br><span class="line"> </span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">table</span> t_student_health_female(</span><br><span class="line">    <span class="keyword">id</span> <span class="built_in">int</span>(<span class="number">20</span>) <span class="keyword">not</span> <span class="literal">null</span> auto_increment <span class="keyword">comment</span> <span class="string">'编号'</span>,</span><br><span class="line">    student_id <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">null</span> <span class="keyword">comment</span> <span class="string">'学生编号'</span>,</span><br><span class="line">    check_date <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'检查日期'</span>,</span><br><span class="line">    heart <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'心'</span>,</span><br><span class="line">    liver <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'肝'</span>,</span><br><span class="line">    spleen <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'脾'</span>,</span><br><span class="line">    lung <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'肺'</span>,</span><br><span class="line">    kidney <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'肾'</span>,</span><br><span class="line">    uterus <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'子宫'</span>,</span><br><span class="line">    note <span class="built_in">VARCHAR</span>(<span class="number">1024</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">comment</span> <span class="string">'备注'</span>,</span><br><span class="line">    PRIMARY <span class="keyword">KEY</span> (<span class="keyword">id</span>)</span><br><span class="line">);</span><br><span class="line"> </span><br><span class="line"><span class="keyword">CREATE</span> <span class="keyword">table</span> t_student_health_male(</span><br><span class="line">    <span class="keyword">id</span> <span class="built_in">int</span>(<span class="number">20</span>) <span class="keyword">not</span> <span class="literal">null</span> auto_increment <span class="keyword">comment</span> <span class="string">'编号'</span>,</span><br><span class="line">    student_id <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">null</span> <span class="keyword">comment</span> <span class="string">'学生编号'</span>,</span><br><span class="line">    check_date <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'检查日期'</span>,</span><br><span class="line">    heart <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'心'</span>,</span><br><span class="line">    liver <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'肝'</span>,</span><br><span class="line">    spleen <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'脾'</span>,</span><br><span class="line">    lung <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'肺'</span>,</span><br><span class="line">    kidney <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'肾'</span>,</span><br><span class="line">    prostate <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'前列腺'</span>,</span><br><span class="line">    note <span class="built_in">VARCHAR</span>(<span class="number">1024</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">comment</span> <span class="string">'备注'</span>,</span><br><span class="line">    PRIMARY <span class="keyword">KEY</span> (<span class="keyword">id</span>)</span><br><span class="line">);</span><br><span class="line"> </span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> t_student_lecture(</span><br><span class="line">    <span class="keyword">id</span> <span class="built_in">int</span>(<span class="number">20</span>) <span class="keyword">not</span> <span class="literal">null</span> auto_increment <span class="keyword">COMMENT</span> <span class="string">'编号'</span>,</span><br><span class="line">    student_id <span class="built_in">int</span>(<span class="number">20</span>) <span class="keyword">not</span> <span class="literal">null</span> <span class="keyword">comment</span> <span class="string">'学生编号'</span>,</span><br><span class="line">    lecture_id <span class="built_in">int</span>(<span class="number">20</span>) <span class="keyword">not</span> <span class="literal">null</span> <span class="keyword">comment</span> <span class="string">'课程编号'</span>,</span><br><span class="line">    grade <span class="built_in">DECIMAL</span>(<span class="number">16</span>,<span class="number">2</span>) <span class="keyword">not</span> <span class="literal">null</span> <span class="keyword">comment</span> <span class="string">'评分'</span>,</span><br><span class="line">    note <span class="built_in">VARCHAR</span>(<span class="number">1024</span>) <span class="keyword">comment</span> <span class="string">'备注'</span>,</span><br><span class="line">    PRIMARY <span class="keyword">KEY</span> (<span class="keyword">id</span>)</span><br><span class="line">);</span><br><span class="line"> </span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> t_student_selfcard(</span><br><span class="line">    <span class="keyword">id</span> <span class="built_in">int</span>(<span class="number">20</span>) <span class="keyword">not</span> <span class="literal">null</span> auto_increment <span class="keyword">COMMENT</span> <span class="string">'编号'</span>,</span><br><span class="line">    student_id <span class="built_in">int</span>(<span class="number">20</span>) <span class="keyword">not</span> <span class="literal">null</span> <span class="keyword">comment</span> <span class="string">'学生编号'</span>,</span><br><span class="line">    <span class="keyword">native</span> <span class="built_in">VARCHAR</span>(<span class="number">60</span>) <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'籍贯'</span>,</span><br><span class="line">    issue_date <span class="built_in">date</span> <span class="keyword">NOT</span> <span class="literal">NULL</span> <span class="keyword">comment</span> <span class="string">'发证日期'</span>,</span><br><span class="line">    end_date <span class="built_in">date</span> <span class="keyword">not</span> <span class="literal">NULL</span> <span class="keyword">COMMENT</span> <span class="string">'结束日期'</span>,</span><br><span class="line">    note <span class="built_in">VARCHAR</span>(<span class="number">1024</span>) <span class="keyword">comment</span> <span class="string">'备注'</span>,</span><br><span class="line">    PRIMARY <span class="keyword">KEY</span> (<span class="keyword">id</span>)</span><br><span class="line">);</span><br></pre></td></tr></table></figure><p></p><h2 id="association"><a href="#association" class="headerlink" title="association"></a>association</h2><p>用t_student和t_student_selfcard演示一对一级联。</p><p>新增Student POJO：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> Long id;</span><br><span class="line">    <span class="keyword">private</span> String cnName;</span><br><span class="line">    <span class="keyword">private</span> Sex sex;</span><br><span class="line">    <span class="keyword">private</span> Long selfCardNo;</span><br><span class="line">    <span class="keyword">private</span> String note;</span><br><span class="line">    <span class="comment">//一对一关系</span></span><br><span class="line">    <span class="keyword">private</span> StudentSelfcard selfCard;</span><br><span class="line">    <span class="comment">// getter，setter略</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p></p><p>StudentSelfcard POJO：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">StudentSelfcard</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> Long id;</span><br><span class="line">    <span class="keyword">private</span> Long studentId;</span><br><span class="line">    <span class="keyword">private</span> String natives;</span><br><span class="line">    <span class="keyword">private</span> Date issueDate;</span><br><span class="line">    <span class="keyword">private</span> Date endDate;</span><br><span class="line">    <span class="keyword">private</span> String note;</span><br><span class="line">    <span class="comment">// getter，setter略</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p></p><p>定义接口StudentSelfcardMapper：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">StudentSelfcardMapper</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> StudentSelfcard <span class="title">findStudentSelfcardByStudentId</span><span class="params">(Long id)</span></span>;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">insertStudentSelfcard</span><span class="params">(StudentSelfcard selfCard)</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p></p><p>创建对应的映射文件StudentSelfcardMapper.xml：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;</span>    </span><br><span class="line">    <span class="meta">&lt;!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"   </span></span><br><span class="line"><span class="meta">"http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;</span>     </span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">"mrbird.leanote.mapper.StudentSelfcardMapper"</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">sql</span> <span class="attr">id</span>=<span class="string">"studentSelfcard_column"</span>&gt;</span></span><br><span class="line">        id,student_id as studentId,native as natives,issue_date as issueDate,</span><br><span class="line">        end_date as endDate,note</span><br><span class="line">    <span class="tag">&lt;/<span class="name">sql</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"findStudentSelfcardByStudentId"</span> <span class="attr">parameterType</span>=<span class="string">"long"</span> </span></span><br><span class="line"><span class="tag">        <span class="attr">resultType</span>=<span class="string">"studentSelfcard"</span>&gt;</span></span><br><span class="line">        select <span class="tag">&lt;<span class="name">include</span> <span class="attr">refid</span>=<span class="string">"studentSelfcard_column"</span>/&gt;</span> </span><br><span class="line">        from t_student_selfcard where student_id = #&#123;studentId&#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">insert</span> <span class="attr">id</span>=<span class="string">"insertStudentSelfcard"</span> <span class="attr">parameterType</span>=<span class="string">"studentSelfcard"</span>&gt;</span></span><br><span class="line">        insert into t_student_selfcard (student_id,native,issue_date,end_date,</span><br><span class="line">        note) values (#&#123;studentId&#125;,#&#123;natives&#125;,#&#123;issueDate&#125;,#&#123;endDate&#125;,#&#123;note&#125;)</span><br><span class="line">    <span class="tag">&lt;/<span class="name">insert</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>接着定义接口StudentMapper：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">StudentMapper</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Student <span class="title">findStudentById</span><span class="params">(Long id)</span></span>;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">createStudent</span><span class="params">(Student s)</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p></p><p>其相对于的映射文件StudentMapper.xml：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;</span>    </span><br><span class="line">    <span class="meta">&lt;!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"   </span></span><br><span class="line"><span class="meta">"http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;</span>     </span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">"mrbird.leanote.mapper.StudentMapper"</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">type</span>=<span class="string">"student"</span> <span class="attr">id</span>=<span class="string">"studentList"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span> <span class="attr">column</span>=<span class="string">"id"</span> <span class="attr">property</span>=<span class="string">"id"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"cnname"</span> <span class="attr">property</span>=<span class="string">"cnName"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"sex"</span> <span class="attr">property</span>=<span class="string">"sex"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">typeHandler</span>=<span class="string">"org.apache.ibatis.type.EnumTypeHandler"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"selfcard_no"</span> <span class="attr">property</span>=<span class="string">"selfCardNo"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"note"</span> <span class="attr">property</span>=<span class="string">"note"</span>/&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 一对一关联，column指定用哪列的值作为select查询的条件，如果有多个值用</span></span><br><span class="line"><span class="comment">            逗号隔开，select指定查询方法--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">association</span> <span class="attr">property</span>=<span class="string">"selfCard"</span> <span class="attr">column</span>=<span class="string">"id"</span> </span></span><br><span class="line"><span class="tag">            <span class="attr">select</span>=<span class="string">"mrbird.leanote.mapper.StudentSelfcardMapper.findStudentSelfcardByStudentId"</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">sql</span> <span class="attr">id</span>=<span class="string">"student_column"</span>&gt;</span></span><br><span class="line">        id,cnname as cnName,sex,selfcard_no as selfCardNo,note </span><br><span class="line">    <span class="tag">&lt;/<span class="name">sql</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"findStudentById"</span> <span class="attr">parameterType</span>=<span class="string">"long"</span> <span class="attr">resultMap</span>=<span class="string">"studentList"</span>&gt;</span></span><br><span class="line">        select </span><br><span class="line">        <span class="tag">&lt;<span class="name">include</span> <span class="attr">refid</span>=<span class="string">"student_column"</span>/&gt;</span> </span><br><span class="line">        from t_student where id = #&#123;id&#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 设置主键回填，供t_student_selfcard的student_id字段使用 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">insert</span> <span class="attr">id</span>=<span class="string">"createStudent"</span> <span class="attr">parameterType</span>=<span class="string">"student"</span> <span class="attr">useGeneratedKeys</span>=<span class="string">"true"</span> </span></span><br><span class="line"><span class="tag">        <span class="attr">keyProperty</span>=<span class="string">"id"</span>&gt;</span></span><br><span class="line">        insert into t_student(cnname,sex,selfcard_no,note) values (#&#123;cnName&#125;,</span><br><span class="line">        #&#123;sex,typeHandler=org.apache.ibatis.type.EnumTypeHandler&#125;,</span><br><span class="line">        #&#123;selfCardNo&#125;,#&#123;note&#125;)</span><br><span class="line">    <span class="tag">&lt;/<span class="name">insert</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>设置别名，指定mapper略。</p><p>先往库表插入值：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">sqlSession = SqlSessionFactoryUtil.openSqlSession();</span><br><span class="line">StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);</span><br><span class="line">StudentSelfcardMapper selfcardMapper = sqlSession.getMapper(StudentSelfcardMapper.class);</span><br><span class="line">Student student = <span class="keyword">new</span> Student();</span><br><span class="line">student.setCnName(<span class="string">"辛久奈"</span>);</span><br><span class="line">student.setNote(<span class="string">"旋涡辛久奈"</span>);</span><br><span class="line">student.setSelfCardNo(<span class="number">10000L</span>);</span><br><span class="line">student.setSex(Sex.FEMALE);</span><br><span class="line"><span class="keyword">int</span> n = studentMapper.createStudent(student);</span><br><span class="line"><span class="keyword">if</span>( n == <span class="number">1</span>)&#123;</span><br><span class="line">    StudentSelfcard selfCard = <span class="keyword">new</span> StudentSelfcard();</span><br><span class="line">    selfCard.setStudentId(student.getId());</span><br><span class="line">    selfCard.setNatives(<span class="string">"福州"</span>);</span><br><span class="line">    selfCard.setIssueDate(<span class="keyword">new</span> Date());</span><br><span class="line">    selfCard.setEndDate(<span class="keyword">new</span> Date());</span><br><span class="line">    selfCard.setNote(<span class="string">"旋涡辛久奈的学生证"</span>);</span><br><span class="line">    selfcardMapper.insertStudentSelfcard(selfCard);</span><br><span class="line">&#125;</span><br><span class="line">sqlSession.commit();</span><br><span class="line">...</span><br></pre></td></tr></table></figure><p></p><p>查询库表：</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">mysql&gt; select * from t_student;</span><br><span class="line">+<span class="comment">----+--------+--------+-------------+------------+</span></span><br><span class="line">| id | cnname | sex    | selfcard_no | note       |</span><br><span class="line">+<span class="comment">----+--------+--------+-------------+------------+</span></span><br><span class="line">| 10 | 辛久奈  | FEMALE |   10000    | 旋涡辛久奈  |</span><br><span class="line">+<span class="comment">----+--------+--------+-------------+------------+</span></span><br><span class="line">1 row in <span class="keyword">set</span> (<span class="number">0.00</span> sec)</span><br><span class="line"> </span><br><span class="line">mysql&gt; <span class="keyword">select</span> * <span class="keyword">from</span> t_student_selfcard;</span><br><span class="line">+<span class="comment">----+------------+--------+------------+------------+--------------------+</span></span><br><span class="line">| id | student_id | native | issue_date | end_date   | note               |</span><br><span class="line">+<span class="comment">----+------------+--------+------------+------------+--------------------+</span></span><br><span class="line">|  2 |         10 | 福州   | 2017-01-06 | 2017-01-06 | 旋涡辛久奈的学生证   |</span><br><span class="line">+<span class="comment">----+------------+--------+------------+------------+--------------------+</span></span><br><span class="line">1 row in <span class="keyword">set</span> (<span class="number">0.00</span> sec)</span><br></pre></td></tr></table></figure><p></p><p>插入成功，现测试级联获取：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">sqlSession = SqlSessionFactoryUtil.openSqlSession();</span><br><span class="line">StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);</span><br><span class="line">Student student = studentMapper.findStudentById(<span class="number">10L</span>);</span><br><span class="line">System.out.println(student.getSelfCard().getNote());</span><br><span class="line">sqlSession.commit();</span><br><span class="line">...</span><br></pre></td></tr></table></figure><p></p><p>控制台输出：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">旋涡辛久奈的学生证</span><br></pre></td></tr></table></figure><p></p><p>success.</p><h2 id="collection"><a href="#collection" class="headerlink" title="collection"></a>collection</h2><p>学生和学生成绩是一对多的关系，所以用t_student和t_student_lecture表练习一对多级联。</p><p>修改Student POJO：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> Long id;</span><br><span class="line">    <span class="keyword">private</span> String cnName;</span><br><span class="line">    <span class="keyword">private</span> Sex sex;</span><br><span class="line">    <span class="keyword">private</span> Long selfCardNo;</span><br><span class="line">    <span class="keyword">private</span> String note;</span><br><span class="line">    <span class="comment">//一对多关联</span></span><br><span class="line">    <span class="keyword">private</span> List&lt;StudentLecture&gt; lectures;</span><br><span class="line">    <span class="comment">// getter，setter略</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p></p><p>新增StudentLecture POJO：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">StudentLecture</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> Long id;</span><br><span class="line">    <span class="keyword">private</span> Long studentId;</span><br><span class="line">    <span class="keyword">private</span> Long lectureId;</span><br><span class="line">    <span class="keyword">private</span> Double grade;</span><br><span class="line">    <span class="keyword">private</span> String note;</span><br><span class="line">    <span class="comment">// getter，setter略</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p></p><p>新建StudentLectureMapper接口：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">StudentLectureMapper</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> List&lt;StudentLecture&gt; <span class="title">getLecturesByStudentId</span><span class="params">(Long studentId)</span></span>;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">insertStudentLecture</span><span class="params">(StudentLecture lecture)</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p></p><p>其对应的映射文件StudentLectureMapper.xml：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;</span>    </span><br><span class="line">    <span class="meta">&lt;!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"   </span></span><br><span class="line"><span class="meta">"http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;</span>     </span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">"mrbird.leanote.mapper.StudentLectureMapper"</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">type</span>=<span class="string">"studentLecture"</span> <span class="attr">id</span>=<span class="string">"lectures"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span> <span class="attr">column</span>=<span class="string">"id"</span> <span class="attr">property</span>=<span class="string">"id"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"student_id"</span> <span class="attr">property</span>=<span class="string">"studentId"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"lecture_id"</span> <span class="attr">property</span>=<span class="string">"lectureId"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"grade"</span> <span class="attr">property</span>=<span class="string">"grade"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"note"</span> <span class="attr">property</span>=<span class="string">"note"</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">sql</span> <span class="attr">id</span>=<span class="string">"student_lecture_column"</span>&gt;</span></span><br><span class="line">        id,student_id as studentId,lecture_id as lectureId,grade,note </span><br><span class="line">    <span class="tag">&lt;/<span class="name">sql</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"getLecturesByStudentId"</span> <span class="attr">parameterType</span>=<span class="string">"long"</span> </span></span><br><span class="line"><span class="tag">        <span class="attr">resultMap</span>=<span class="string">"lectures"</span>&gt;</span></span><br><span class="line">        select <span class="tag">&lt;<span class="name">include</span> <span class="attr">refid</span>=<span class="string">"student_lecture_column"</span>/&gt;</span> </span><br><span class="line">        from t_student_lecture where student_id = #&#123;studentId&#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">insert</span> <span class="attr">id</span>=<span class="string">"insertStudentLecture"</span> <span class="attr">parameterType</span>=<span class="string">"student"</span>&gt;</span></span><br><span class="line">        &lt;![CDATA[</span><br><span class="line">            insert into t_student_lecture(student_id,lecture_id,grade,note) </span><br><span class="line">            values (#&#123;studentId&#125;,#&#123;lectureId&#125;,#&#123;grade&#125;,#&#123;note&#125;)</span><br><span class="line">        ]]&gt;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">insert</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>修改StudentMapper.xml：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;</span>    </span><br><span class="line">    <span class="meta">&lt;!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"   </span></span><br><span class="line"><span class="meta">"http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;</span>     </span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">"mrbird.leanote.mapper.StudentMapper"</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">type</span>=<span class="string">"student"</span> <span class="attr">id</span>=<span class="string">"studentList"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span> <span class="attr">column</span>=<span class="string">"id"</span> <span class="attr">property</span>=<span class="string">"id"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"cnname"</span> <span class="attr">property</span>=<span class="string">"cnName"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"sex"</span> <span class="attr">property</span>=<span class="string">"sex"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">typeHandler</span>=<span class="string">"org.apache.ibatis.type.EnumTypeHandler"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"selfcard_no"</span> <span class="attr">property</span>=<span class="string">"selfCardNo"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"note"</span> <span class="attr">property</span>=<span class="string">"note"</span>/&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 一对多关联，column指定用哪列的值作为select查询的条件，如果由多个值用</span></span><br><span class="line"><span class="comment">            逗号隔开，select指定查询方法--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">collection</span> <span class="attr">property</span>=<span class="string">"lectures"</span> <span class="attr">column</span>=<span class="string">"id"</span> </span></span><br><span class="line"><span class="tag">            <span class="attr">select</span>=<span class="string">"mrbird.leanote.mapper.StudentLectureMapper.getLecturesByStudentId"</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">sql</span> <span class="attr">id</span>=<span class="string">"student_column"</span>&gt;</span></span><br><span class="line">        id,cnname as cnName,sex,selfcard_no as selfCardNo,note </span><br><span class="line">    <span class="tag">&lt;/<span class="name">sql</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"findStudentById"</span> <span class="attr">parameterType</span>=<span class="string">"long"</span> <span class="attr">resultMap</span>=<span class="string">"studentList"</span>&gt;</span></span><br><span class="line">        select <span class="tag">&lt;<span class="name">include</span> <span class="attr">refid</span>=<span class="string">"student_column"</span>/&gt;</span> </span><br><span class="line">        from t_student where id = #&#123;id&#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 设置主键回填，供t_student_selfcard的student_id字段使用 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">insert</span> <span class="attr">id</span>=<span class="string">"createStudent"</span> <span class="attr">parameterType</span>=<span class="string">"student"</span> <span class="attr">useGeneratedKeys</span>=<span class="string">"true"</span> </span></span><br><span class="line"><span class="tag">        <span class="attr">keyProperty</span>=<span class="string">"id"</span>&gt;</span></span><br><span class="line">        insert into t_student(cnname,sex,selfcard_no,note) values (#&#123;cnName&#125;,</span><br><span class="line">        #&#123;sex,typeHandler=org.apache.ibatis.type.EnumTypeHandler&#125;,</span><br><span class="line">        #&#123;selfCardNo&#125;,#&#123;note&#125;)</span><br><span class="line">    <span class="tag">&lt;/<span class="name">insert</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>先插入一些测试数据：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">sqlSession = SqlSessionFactoryUtil.openSqlSession();</span><br><span class="line">StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);</span><br><span class="line">StudentLectureMapper lectureMapper = sqlSession.getMapper(StudentLectureMapper.class);</span><br><span class="line">Student student = <span class="keyword">new</span> Student();</span><br><span class="line">student.setCnName(<span class="string">"水门"</span>);</span><br><span class="line">student.setSelfCardNo(<span class="number">11111L</span>);</span><br><span class="line">student.setNote(<span class="string">"波风水门"</span>);</span><br><span class="line">student.setSex(Sex.MALE);</span><br><span class="line"><span class="keyword">int</span> n = studentMapper.createStudent(student);</span><br><span class="line"><span class="keyword">if</span>(n == <span class="number">1</span>)&#123;</span><br><span class="line">    Long studentId = student.getId();</span><br><span class="line">    String[] noteArr = <span class="keyword">new</span> String[]&#123;<span class="string">"语文成绩"</span>,<span class="string">"数学成绩"</span>,<span class="string">"英语成绩"</span>&#125;;</span><br><span class="line">    Double[] gradeArr = <span class="keyword">new</span> Double[]&#123;<span class="number">99.0</span>,<span class="number">100.0</span>,<span class="number">98.0</span>&#125;;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;noteArr.length;i++)&#123;</span><br><span class="line">        StudentLecture lecture = <span class="keyword">new</span> StudentLecture();</span><br><span class="line">        lecture.setStudentId(studentId);</span><br><span class="line">        lecture.setLectureId(Long.valueOf(i));</span><br><span class="line">        lecture.setGrade(gradeArr[i]);</span><br><span class="line">        lecture.setNote(noteArr[i]);</span><br><span class="line">        lectureMapper.insertStudentLecture(lecture);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">sqlSession.commit();</span><br><span class="line">...</span><br></pre></td></tr></table></figure><p></p><p>查询数据库：</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">mysql&gt; select * from t_student;</span><br><span class="line">+<span class="comment">----+--------+--------+-------------+------------+</span></span><br><span class="line">| id | cnname | sex    | selfcard_no | note       |</span><br><span class="line">+<span class="comment">----+--------+--------+-------------+------------+</span></span><br><span class="line">| 10 | 辛久奈 | FEMALE |       10000 | 旋涡辛久奈  |</span><br><span class="line">| 12 | 水门   | MALE   |       11111 | 波风水门    |</span><br><span class="line">+<span class="comment">----+--------+--------+-------------+------------+</span></span><br><span class="line">2 rows in <span class="keyword">set</span> (<span class="number">0.01</span> sec)</span><br><span class="line"> </span><br><span class="line">mysql&gt; <span class="keyword">select</span> * <span class="keyword">from</span> t_student_lecture;</span><br><span class="line">+<span class="comment">----+------------+------------+--------+----------+</span></span><br><span class="line">| id | student_id | lecture_id | grade  | note     |</span><br><span class="line">+<span class="comment">----+------------+------------+--------+----------+</span></span><br><span class="line">|  1 |         12 |          0 |  99.00 | 语文成绩  |</span><br><span class="line">|  2 |         12 |          1 | 100.00 | 数学成绩  |</span><br><span class="line">|  3 |         12 |          2 |  98.00 | 英语成绩  |</span><br><span class="line">+<span class="comment">----+------------+------------+--------+----------+</span></span><br><span class="line">3 rows in <span class="keyword">set</span> (<span class="number">0.00</span> sec)</span><br></pre></td></tr></table></figure><p></p><p>插入成功，现测试级联获取lectures：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">sqlSession = SqlSessionFactoryUtil.openSqlSession();</span><br><span class="line">StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);</span><br><span class="line">Student student = studentMapper.findStudentById(<span class="number">12L</span>);</span><br><span class="line">List&lt;StudentLecture&gt; lectures = student.getLectures();</span><br><span class="line"><span class="keyword">for</span>(StudentLecture l : lectures)&#123;</span><br><span class="line">    System.out.println(l.getNote()+<span class="string">"："</span>+l.getGrade());</span><br><span class="line">&#125; </span><br><span class="line">...</span><br></pre></td></tr></table></figure><p></p><p>控制台输出：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">语文成绩：99.0</span><br><span class="line">数学成绩：100.0</span><br><span class="line">英语成绩：98.0</span><br></pre></td></tr></table></figure><p></p><p>success.</p><h2 id="discriminator"><a href="#discriminator" class="headerlink" title="discriminator"></a>discriminator</h2><p>鉴别器其实同其他级联一样，只不过是多了个鉴别的过程罢了。</p><p>为了学习鉴别器，我们向t_student_health_female和t_student_health_male中插入一组数据：</p><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> <span class="string">`t_student_health_female`</span></span><br><span class="line"><span class="keyword">VALUES</span>(</span><br><span class="line">    <span class="number">1</span>,</span><br><span class="line">    <span class="string">'10'</span>,</span><br><span class="line">    <span class="string">'2017-1-6'</span>,</span><br><span class="line">    <span class="string">'心正常'</span>,</span><br><span class="line">    <span class="string">'肝正常'</span>,</span><br><span class="line">    <span class="string">'脾正常'</span>,</span><br><span class="line">    <span class="string">'肺正常'</span>,</span><br><span class="line">    <span class="string">'肾正常'</span>,</span><br><span class="line">    <span class="string">'子宫正常'</span>,</span><br><span class="line">    <span class="string">'健康'</span>);</span><br><span class="line"> </span><br><span class="line"><span class="keyword">INSERT</span> <span class="keyword">INTO</span> <span class="string">`t_student_health_male`</span></span><br><span class="line"><span class="keyword">VALUES</span>(</span><br><span class="line">    <span class="number">1</span>,</span><br><span class="line">    <span class="string">'12'</span>,</span><br><span class="line">    <span class="string">'2017-1-6'</span>,</span><br><span class="line">    <span class="string">'心脏良好'</span>,</span><br><span class="line">    <span class="string">'肝良好'</span>,</span><br><span class="line">    <span class="string">'脾良好'</span>,</span><br><span class="line">    <span class="string">'肺良好'</span>,</span><br><span class="line">    <span class="string">'肾良好'</span>,</span><br><span class="line">    <span class="string">'前列腺良好'</span>,</span><br><span class="line">    <span class="string">'健康'</span>);</span><br></pre></td></tr></table></figure><p></p><p>其对应的实体类StudentHealthFemale和StudentHealthMale略。</p><p>新增两个POJO：MaleStudent和FemaleStudent均继承自Student：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MaleStudent</span> <span class="keyword">extends</span> <span class="title">Student</span></span>&#123;</span><br><span class="line">    <span class="keyword">private</span> List&lt;StudentHealthMale&gt; studentHealthMaleList;</span><br><span class="line">   <span class="comment">// getter，setter略</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p></p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">FemaleStudent</span> <span class="keyword">extends</span> <span class="title">Student</span></span>&#123;</span><br><span class="line">    <span class="keyword">private</span> List&lt;StudentHealthFemale&gt; studentHealthFemaleList;</span><br><span class="line">    <span class="comment">// getter，setter略</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>接着编写两个接口StudentHealthMaleMapper和StudentHealthFemaleMapper，包含一个根据studentId获取health的抽象方法：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> mrbird.leanote.pojo.StudentHealthMale;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">StudentHealthMaleMapper</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> StudentHealthMale <span class="title">findStudentHealthMaleByStudentId</span><span class="params">(Long studentId)</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p></p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> mrbird.leanote.pojo.StudentHealthFemale;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">StudentHealthFemaleMapper</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> StudentHealthFemale <span class="title">findStudentHealthFemaleByStudentId</span><span class="params">(Long studentId)</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>各自对应的映射器：</p><p>StudentHealthMaleMapper.xml：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;</span>    </span><br><span class="line">    <span class="meta">&lt;!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"   </span></span><br><span class="line"><span class="meta">"http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;</span>     </span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">"mrbird.leanote.mapper.StudentHealthMaleMapper"</span>&gt;</span>  </span><br><span class="line">	<span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"findStudentHealthMaleByStudentId"</span> <span class="attr">parameterType</span>=<span class="string">"long"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">resultType</span>=<span class="string">"studentHealthMale"</span>&gt;</span></span><br><span class="line">        select * from t_student_health_male where student_id = #&#123;studentId&#125;</span><br><span class="line">	<span class="tag">&lt;/<span class="name">select</span>&gt;</span>	</span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>因为在MyBatis配置文件中配置了<code>&lt;setting name=&quot;mapUnderscoreToCamelCase&quot; value=&quot;true&quot;/&gt;</code>，并且数据库命名规范，所以这里可以用select * from…</p><p>studentHealthFemaleMapper.xml：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"   </span></span><br><span class="line"><span class="meta">"http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;</span>     </span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">"mrbird.leanote.mapper.StudentHealthFemaleMapper"</span>&gt;</span>  </span><br><span class="line">	<span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"findStudentHealthFemaleByStudentId"</span> <span class="attr">parameterType</span>=<span class="string">"long"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">resultType</span>=<span class="string">"studentHealthFemale"</span>&gt;</span></span><br><span class="line">        select * from t_student_health_female where student_id = #&#123;studentId&#125;</span><br><span class="line">	<span class="tag">&lt;/<span class="name">select</span>&gt;</span>	</span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>接下来就是重点了，我们修改StudentMapper.xml：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;</span>    </span><br><span class="line">    <span class="meta">&lt;!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"   </span></span><br><span class="line"><span class="meta">"http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;</span>     </span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">"mrbird.leanote.mapper.StudentMapper"</span>&gt;</span> </span><br><span class="line">    <span class="comment">&lt;!-- 定义maleStudentList，类型为“maleStudent”。这是一个一对多关联，一个学生可以体检多次。</span></span><br><span class="line"><span class="comment">        调用的方法为findStudentHealthMaleByStudentId。</span></span><br><span class="line"><span class="comment">        正如其POJO继承Student那样，resultMap也同样继承自studentList--&gt;</span> </span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">type</span>=<span class="string">"maleStudent"</span> <span class="attr">id</span>=<span class="string">"maleStudentList"</span> <span class="attr">extends</span>=<span class="string">"studentList"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">collection</span> <span class="attr">property</span>=<span class="string">"studentHealthMaleList"</span> <span class="attr">column</span>=<span class="string">"id"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">select</span>=<span class="string">"mrbird.leanote.mapper.StudentHealthMaleMapper</span></span></span><br><span class="line"><span class="tag"><span class="string">                .findStudentHealthMaleByStudentId"</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">type</span>=<span class="string">"femaleStudent"</span> <span class="attr">id</span>=<span class="string">"femaleStudentList"</span> <span class="attr">extends</span>=<span class="string">"studentList"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">collection</span> <span class="attr">property</span>=<span class="string">"studentHealthFemaleList"</span> <span class="attr">column</span>=<span class="string">"id"</span> </span></span><br><span class="line"><span class="tag">            <span class="attr">select</span>=<span class="string">"mrbird.leanote.mapper.StudentHealthFemaleMapper</span></span></span><br><span class="line"><span class="tag"><span class="string">                .findStudentHealthFemaleByStudentId"</span>/&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">type</span>=<span class="string">"student"</span> <span class="attr">id</span>=<span class="string">"studentList"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span> <span class="attr">column</span>=<span class="string">"id"</span> <span class="attr">property</span>=<span class="string">"id"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"cnname"</span> <span class="attr">property</span>=<span class="string">"cnName"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"sex"</span> <span class="attr">property</span>=<span class="string">"sex"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"selfcard_no"</span> <span class="attr">property</span>=<span class="string">"selfCardNo"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"note"</span> <span class="attr">property</span>=<span class="string">"note"</span>/&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- 配置鉴别器，类似于switch，用于鉴别的列为“sex”，</span></span><br><span class="line"><span class="comment">            值为MALE时结果集为maleStudentList</span></span><br><span class="line"><span class="comment">            值为FEMALE时结果集为femaleStudentList --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">discriminator</span> <span class="attr">javaType</span>=<span class="string">"string"</span> <span class="attr">column</span>=<span class="string">"sex"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">case</span> <span class="attr">value</span>=<span class="string">"MALE"</span> <span class="attr">resultMap</span>=<span class="string">"maleStudentList"</span>&gt;</span><span class="tag">&lt;/<span class="name">case</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">case</span> <span class="attr">value</span>=<span class="string">"FEMALE"</span> <span class="attr">resultMap</span>=<span class="string">"femaleStudentList"</span>&gt;</span><span class="tag">&lt;/<span class="name">case</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">discriminator</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">sql</span> <span class="attr">id</span>=<span class="string">"student_column"</span>&gt;</span></span><br><span class="line">        id,cnname as cnName,sex,selfcard_no as selfCardNo,note </span><br><span class="line">    <span class="tag">&lt;/<span class="name">sql</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"findStudentById"</span> <span class="attr">parameterType</span>=<span class="string">"long"</span> <span class="attr">resultMap</span>=<span class="string">"studentList"</span>&gt;</span></span><br><span class="line">        select <span class="tag">&lt;<span class="name">include</span> <span class="attr">refid</span>=<span class="string">"student_column"</span>/&gt;</span> </span><br><span class="line">        from t_student where id = #&#123;id&#125;</span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>测试一下：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">sqlSession = SqlSessionFactoryUtil.openSqlSession();</span><br><span class="line">StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);</span><br><span class="line">MaleStudent student = (MaleStudent) studentMapper.findStudentById(<span class="number">12L</span>);</span><br><span class="line">System.out.println(student.getCnName()+<span class="string">"的"</span>+</span><br><span class="line">    student.getStudentHealthMaleList().get(<span class="number">0</span>).getProstate());</span><br><span class="line">...</span><br></pre></td></tr></table></figure><p></p><p>页面输出：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">水门的前例腺良好</span><br></pre></td></tr></table></figure><p></p><p>(≖ ‿ ≖)✧</p><h2 id="延迟加载"><a href="#延迟加载" class="headerlink" title="延迟加载"></a>延迟加载</h2><p>假如一次性将所有与Student有关的信息都加载出来，这必定会造成性能的问题，如：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;</span>    </span><br><span class="line">    <span class="meta">&lt;!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"   </span></span><br><span class="line"><span class="meta">"http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;</span>     </span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">"mrbird.leanote.mapper.StudentMapper"</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">type</span>=<span class="string">"student"</span> <span class="attr">id</span>=<span class="string">"studentList"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span> <span class="attr">column</span>=<span class="string">"id"</span> <span class="attr">property</span>=<span class="string">"id"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"cnname"</span> <span class="attr">property</span>=<span class="string">"cnName"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"sex"</span> <span class="attr">property</span>=<span class="string">"sex"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"selfcard_no"</span> <span class="attr">property</span>=<span class="string">"selfCardNo"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"note"</span> <span class="attr">property</span>=<span class="string">"note"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">association</span> <span class="attr">property</span>=<span class="string">"selfCard"</span> <span class="attr">column</span>=<span class="string">"id"</span> </span></span><br><span class="line"><span class="tag">            <span class="attr">select</span>=<span class="string">"mrbird.leanote.mapper.StudentSelfcardMapper</span></span></span><br><span class="line"><span class="tag"><span class="string">                .findStudentSelfcardByStudentId"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">collection</span> <span class="attr">property</span>=<span class="string">"lectures"</span> <span class="attr">column</span>=<span class="string">"id"</span> </span></span><br><span class="line"><span class="tag">            <span class="attr">select</span>=<span class="string">"mrbird.leanote.mapper.StudentLectureMapper</span></span></span><br><span class="line"><span class="tag"><span class="string">                .getLecturesByStudentId"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">discriminator</span> <span class="attr">javaType</span>=<span class="string">"string"</span> <span class="attr">column</span>=<span class="string">"sex"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">case</span> <span class="attr">value</span>=<span class="string">"MALE"</span> <span class="attr">resultMap</span>=<span class="string">"maleStudentList"</span>&gt;</span><span class="tag">&lt;/<span class="name">case</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">case</span> <span class="attr">value</span>=<span class="string">"FEMALE"</span> <span class="attr">resultMap</span>=<span class="string">"femaleStudentList"</span>&gt;</span><span class="tag">&lt;/<span class="name">case</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">discriminator</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line">  ...  </span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>MyBatis的延迟加载策略可以很好的应对这种情况。只需在mybatis-config.xml中配置：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">settings</span>&gt;</span></span><br><span class="line">    ...</span><br><span class="line">    <span class="comment">&lt;!-- 开启延迟加载 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">setting</span> <span class="attr">name</span>=<span class="string">"lazyLoadingEnabled"</span> <span class="attr">value</span>=<span class="string">"true"</span>/&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 关闭按层级加载 --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">setting</span> <span class="attr">name</span>=<span class="string">"aggressiveLazyLoading"</span> <span class="attr">value</span>=<span class="string">"false"</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">settings</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>然后我们在级联标签上可以自由的配置fetchType=”lazy”或者fetchType=”eager”来改变加载策略。</p><blockquote><p>eager 英[ˈi:gə(r)] 美[ˈiɡɚ] adj. 急切; 渴望的; 热心的; 热切的，热情洋溢的;</p></blockquote><h2 id="另外一种级联"><a href="#另外一种级联" class="headerlink" title="另外一种级联"></a>另外一种级联</h2><p>所谓的另外一种级联就是用一条sql查出所有学生的信息，没有性能问题。</p><p>在StudentMapper中定义一个查找所有学生信息的抽象方法：</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> List&lt;Student&gt; <span class="title">finAllStudentMsg</span><span class="params">()</span></span>;</span><br></pre></td></tr></table></figure><p></p><p>其映射文件如下：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;</span>    </span><br><span class="line">    <span class="meta">&lt;!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"   </span></span><br><span class="line"><span class="meta">"http://mybatis.org/dtd/mybatis-3-mapper.dtd"&gt;</span>     </span><br><span class="line"><span class="tag">&lt;<span class="name">mapper</span> <span class="attr">namespace</span>=<span class="string">"mrbird.leanote.mapper.StudentMapper"</span>&gt;</span> </span><br><span class="line">    <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"finAllStudentMsg"</span> <span class="attr">resultMap</span>=<span class="string">"allStudentList"</span>&gt;</span></span><br><span class="line">        select s.id,s.cnname,s.sex,s.selfcard_no,s.note as snote,</span><br><span class="line">        IF (s.sex = 'MALE',shm.id,shf.id) as hid,</span><br><span class="line">        IF (s.sex = 'MALE',shm.check_date,shf.check_date) as checkDate,</span><br><span class="line">        IF (s.sex = 'MALE',shm.heart,shf.heart) as heart,</span><br><span class="line">        IF (s.sex = 'MALE',shm.liver,shf.liver) as liver,</span><br><span class="line">        IF (s.sex = 'MALE',shm.spleen,shf.spleen) as spleen,</span><br><span class="line">        IF (s.sex = 'MALE',shm.lung,shf.lung) as lung,</span><br><span class="line">        IF (s.sex = 'MALE',shm.kidney,shf.kidney) as kidney,</span><br><span class="line">        IF (s.sex = 'MALE',shm.note,shf.note) as hnote,</span><br><span class="line">        shm.prostate,shf.uterus,</span><br><span class="line">        ss.id as ssid,ss.native as natives,</span><br><span class="line">        ss.issue_date as issueDate,ss.end_date as endDate,</span><br><span class="line">        ss.note as ssNote,</span><br><span class="line">        sl.id as slid,sl.lecture_id as lectureId,sl.grade,</span><br><span class="line">        sl.note as slNote </span><br><span class="line">        FROM t_student s </span><br><span class="line">        LEFT JOIN t_student_health_male shm on s.id = shm.student_id </span><br><span class="line">        LEFT JOIN t_student_health_female shf on s.id = shf.student_id </span><br><span class="line">        LEFT JOIN t_student_selfcard ss on s.id = ss.student_id </span><br><span class="line">        LEFT JOIN t_student_lecture sl on s.id = sl.student_id </span><br><span class="line">    <span class="tag">&lt;/<span class="name">select</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">type</span>=<span class="string">"student"</span> <span class="attr">id</span>=<span class="string">"allStudentList"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">id</span> <span class="attr">column</span>=<span class="string">"id"</span> <span class="attr">property</span>=<span class="string">"id"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"cnname"</span> <span class="attr">property</span>=<span class="string">"cnName"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"sex"</span> <span class="attr">property</span>=<span class="string">"sex"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"selfcard_no"</span> <span class="attr">property</span>=<span class="string">"selfCardNo"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">result</span> <span class="attr">column</span>=<span class="string">"snote"</span> <span class="attr">property</span>=<span class="string">"note"</span>/&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- javaType属性告诉MyBtis用哪个类去映射这些字段 --&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">association</span> <span class="attr">property</span>=<span class="string">"selfCard"</span> <span class="attr">column</span>=<span class="string">"id"</span> <span class="attr">javaType</span>=<span class="string">"studentSelfcard"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"id"</span> <span class="attr">column</span>=<span class="string">"ssid"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"studentId"</span> <span class="attr">column</span>=<span class="string">"id"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"natives"</span> <span class="attr">column</span>=<span class="string">"natives"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"issueDate"</span> <span class="attr">column</span>=<span class="string">"issueDate"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"endDate"</span> <span class="attr">column</span>=<span class="string">"endDate"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"note"</span> <span class="attr">column</span>=<span class="string">"ssNote"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">association</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">collection</span> <span class="attr">property</span>=<span class="string">"lectures"</span> <span class="attr">ofType</span>=<span class="string">"studentLecture"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"id"</span> <span class="attr">column</span>=<span class="string">"slid"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"studentId"</span> <span class="attr">column</span>=<span class="string">"id"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"lectureId"</span> <span class="attr">column</span>=<span class="string">"lectureId"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"grade"</span> <span class="attr">column</span>=<span class="string">"grade"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"note"</span> <span class="attr">column</span>=<span class="string">"slNote"</span>/&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">collection</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">discriminator</span> <span class="attr">javaType</span>=<span class="string">"string"</span> <span class="attr">column</span>=<span class="string">"sex"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">case</span> <span class="attr">value</span>=<span class="string">"MALE"</span> <span class="attr">resultMap</span>=<span class="string">"maleStudentList"</span>&gt;</span><span class="tag">&lt;/<span class="name">case</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">case</span> <span class="attr">value</span>=<span class="string">"FEMALE"</span> <span class="attr">resultMap</span>=<span class="string">"femaleStudentList"</span>&gt;</span><span class="tag">&lt;/<span class="name">case</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">discriminator</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">type</span>=<span class="string">"maleStudent"</span> <span class="attr">id</span>=<span class="string">"maleStudentList"</span> <span class="attr">extends</span>=<span class="string">"allStudentList"</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!-- ofType属性指定了其泛型 --&gt;</span></span><br><span class="line">    	<span class="tag">&lt;<span class="name">collection</span> <span class="attr">property</span>=<span class="string">"studentHealthMaleList"</span> <span class="attr">ofType</span>=<span class="string">"studentHealthMale"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">id</span> <span class="attr">property</span>=<span class="string">"id"</span> <span class="attr">column</span>=<span class="string">"hid"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"studentId"</span> <span class="attr">column</span>=<span class="string">"id"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"checkDate"</span> <span class="attr">column</span>=<span class="string">"checkDate"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"heart"</span> <span class="attr">column</span>=<span class="string">"heart"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"liver"</span> <span class="attr">column</span>=<span class="string">"liver"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"spleen"</span> <span class="attr">column</span>=<span class="string">"spleen"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"lung"</span> <span class="attr">column</span>=<span class="string">"lung"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"kidney"</span> <span class="attr">column</span>=<span class="string">"kidney"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"prostate"</span> <span class="attr">column</span>=<span class="string">"prostate"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"note"</span> <span class="attr">column</span>=<span class="string">"hnote"</span>/&gt;</span></span><br><span class="line">    	<span class="tag">&lt;/<span class="name">collection</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">resultMap</span> <span class="attr">type</span>=<span class="string">"femaleStudent"</span> <span class="attr">id</span>=<span class="string">"femaleStudentList"</span> <span class="attr">extends</span>=<span class="string">"allStudentList"</span>&gt;</span></span><br><span class="line">    	<span class="tag">&lt;<span class="name">collection</span> <span class="attr">property</span>=<span class="string">"studentHealthFemaleList"</span> <span class="attr">ofType</span>=<span class="string">"studentHealthFemale"</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">id</span> <span class="attr">property</span>=<span class="string">"id"</span> <span class="attr">column</span>=<span class="string">"hid"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"studentId"</span> <span class="attr">column</span>=<span class="string">"id"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"checkDate"</span> <span class="attr">column</span>=<span class="string">"checkDate"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"heart"</span> <span class="attr">column</span>=<span class="string">"heart"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"liver"</span> <span class="attr">column</span>=<span class="string">"liver"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"spleen"</span> <span class="attr">column</span>=<span class="string">"spleen"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"lung"</span> <span class="attr">column</span>=<span class="string">"lung"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"kidney"</span> <span class="attr">column</span>=<span class="string">"kidney"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"uterus"</span> <span class="attr">column</span>=<span class="string">"uterus"</span>/&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">result</span> <span class="attr">property</span>=<span class="string">"note"</span> <span class="attr">column</span>=<span class="string">"hnote"</span>/&gt;</span></span><br><span class="line">    	<span class="tag">&lt;/<span class="name">collection</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resultMap</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">mapper</span>&gt;</span></span><br></pre></td></tr></table></figure><p></p><p>测试finAllStudentMsg方法：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">...</span><br><span class="line">sqlSession = SqlSessionFactoryUtil.openSqlSession();</span><br><span class="line">StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);</span><br><span class="line">List<span class="tag">&lt;<span class="name">Student</span>&gt;</span> students = studentMapper.finAllStudentMsg();</span><br><span class="line">for(Student student : students)&#123;</span><br><span class="line">    if("MALE".equalsIgnoreCase(student.getSex().toString()))&#123;</span><br><span class="line">        MaleStudent male = (MaleStudent) student;</span><br><span class="line">        System.out.println(male.getCnName()+"的卡号："+male.getSelfCardNo());</span><br><span class="line">        StudentSelfcard selfcard = male.getSelfCard();</span><br><span class="line">        System.out.println("来自："+selfcard.getNatives()+","+selfcard.getNote());</span><br><span class="line">        List<span class="tag">&lt;<span class="name">StudentLecture</span>&gt;</span> lectures = male.getLectures();</span><br><span class="line">        for(StudentLecture le : lectures)&#123;</span><br><span class="line">            System.out.println(le.getNote()+"："+le.getGrade());</span><br><span class="line">        &#125;</span><br><span class="line">        List<span class="tag">&lt;<span class="name">StudentHealthMale</span>&gt;</span> healthMales = male.getStudentHealthMaleList();</span><br><span class="line">        for(StudentHealthMale healthMale : healthMales)&#123;</span><br><span class="line">            System.out.println(healthMale.getCheckDate()+"，"+healthMale.getProstate());</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;else&#123;</span><br><span class="line">    	FemaleStudent female = (FemaleStudent) student;</span><br><span class="line">    	System.out.println(female.getCnName()+"的卡号："+female.getSelfCardNo());</span><br><span class="line">    	StudentSelfcard selfcard = female.getSelfCard();</span><br><span class="line">    	System.out.println("来自："+selfcard.getNatives()+","+selfcard.getNote());</span><br><span class="line">    	List<span class="tag">&lt;<span class="name">StudentLecture</span>&gt;</span> lectures = female.getLectures();</span><br><span class="line">    	for(StudentLecture le : lectures)&#123;</span><br><span class="line">            System.out.println(le.getNote()+"："+le.getGrade());</span><br><span class="line">    	&#125;</span><br><span class="line">    	List<span class="tag">&lt;<span class="name">StudentHealthFemale</span>&gt;</span> healthFemales = female.getStudentHealthFemaleList();</span><br><span class="line">    	for(StudentHealthFemale healthfemale : healthFemales)&#123;</span><br><span class="line">            System.out.println(healthfemale.getCheckDate()+"，"+healthfemale.getUterus());</span><br><span class="line">    	&#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">...</span><br></pre></td></tr></table></figure><p></p><p>控制台输出：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">辛久奈的卡号：10000</span><br><span class="line">来自：福州,旋涡辛久奈的学生证</span><br><span class="line">语文成绩：99.0</span><br><span class="line">数学成绩：99.0</span><br><span class="line">英语成绩：99.0</span><br><span class="line">2017-1-6，子宫正常</span><br><span class="line">水门的卡号：11111</span><br><span class="line">来自：厦门,波风水门的学生证</span><br><span class="line">语文成绩：99.0</span><br><span class="line">数学成绩：100.0</span><br><span class="line">英语成绩：98.0</span><br><span class="line">2017-1-6，前例腺良好</span><br></pre></td></tr></table></figure><p></p><p>这种方式比较直观明了，但是SQL编写起来较为繁琐。</p><blockquote><p><a href="https://book.douban.com/subject/26858114/" target="_blank" rel="noopener">《深入浅出MyBatis技术原理与实战》</a>读书笔记</p></blockquote><script>$(".post-body a").not(".thispage").addClass("ignore-href").attr("target","_blank")</script></div><div></div><div><div style="padding:10px 0;margin:20px auto;width:90%;text-align:center;color:#878787"><div>请作者喝瓶肥宅水~</div><button id="rewardButton" style="margin-top:10px" disable="enable" onclick='var e=document.getElementById("QR");"none"===e.style.display?e.style.display="block":e.style.display="none"'><span style="height:46px;width:46px;line-height:46px;border-radius:50%;color:#fe5f55;font-weight:600;background:#ffd5be;border:none;box-shadow:0 4px 8px 0 rgba(255,213,190,.4)">￥</span></button><div id="QR" style="display:none"><div id="wechat" style="display:inline-block"><img id="wechat_qr" src="/img/wechat_pay.png" alt="MrBird WeChat Pay"></div><div id="alipay" style="display:inline-block"><img id="alipay_qr" src="/img/ali_pay.png" alt="MrBird Alipay"></div></div></div><style>#QR img{width:auto;margin:.8em 1em 0 1em}</style></div><div><ul class="post-copyright"><li class="post-copyright-author"><strong>本文作者：</strong> MrBird</li><li class="post-copyright-link"><strong>本文链接：</strong> <a href="http://mrbird.cc/MyBatis级联.html" title="MyBatis级联">http://mrbird.cc/MyBatis级联.html</a></li><li class="post-copyright-license"><strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明出处！</li></ul></div><footer class="post-footer"><div class="post-tags" style="margin-bottom:1.3rem"><a href="/tags/MyBatis/" rel="tag"># MyBatis</a></div><div class="post-nav"><div class="post-nav-next post-nav-item"><a href="/MyBatis映射器.html" rel="next" title="MyBatis映射器"><i class="fa fa-chevron-left"></i> MyBatis映射器</a></div><span class="post-nav-divider"></span><div class="post-nav-prev post-nav-item"><a href="/MyBatis-Cache.html" rel="prev" title="MyBatis Cache">MyBatis Cache <i class="fa fa-chevron-right"></i></a></div></div></footer></article><hr><div id="container"></div><div class="post-spread"><div id="comment-div"></div><style>.valine .vlist{margin-bottom:3rem}.valine .vwrap .vcontrol .col.col-60{text-align:left}.valine .vlist .vcard .vhead,.valine .vlist .vcard section .vfooter{text-align:left}.valine .vlist .vcard section{padding-bottom:.5rem!important}.vname{color:#42b983!important}.valine .vinfo .col{text-align:left;margin-left:-27rem}div#comment-div{margin-bottom:-8rem}.valine .vlist .vcard .vcontent .code,.valine .vlist .vcard .vcontent code,.valine .vlist .vcard .vcontent pre{background:#fbfbfb}.valine .vlist .vcard .vcontent a{color:#42b983}.valine .vlist .vcard .vimg{border-radius:3px}.valine .vbtn{border-radius:2px;padding:.3rem 1.25rem}.valine .vbtn:active,.valine .vbtn:hover{color:#42b983;border-color:#42b983;background-color:#fff}.valine .vwrap .vheader .vinput:focus{border-bottom-color:#42b983}.valine .vlist .vcard .vcontent.expand:before{background:-webkit-gradient(linear,left top,left bottom,from(hsla(0,0%,100%,0)),to(hsla(0,0%,100%,.2)));background:linear-gradient(180deg,hsla(0,0%,100%,0),hsla(0,0%,100%,.2))}.valine .vlist .vcard .vcontent.expand:after{content:"点击展开";font-size:.4rem;text-align:right;left:-1rem;background:hsla(0,0%,100%,.2)}.valine .vlist .vcard section .vfooter .vat{color:#b3b3b3}.valine .vlist .vcard section .vfooter .vat:hover{color:#42b983}.vcontent img{margin:0}.valine .info{display:none}</style><script type="text/javascript" src="/js/av.min.js"></script><script type="text/javascript" src="/js/Valine.min.js"></script><script type="text/javascript" src="/js/activate-power-mode.js"></script><script>POWERMODE.colorful=!0,POWERMODE.shake=!1,document.body.addEventListener("input",POWERMODE),new Valine({el:"#comment-div",notify:!1,verify:!0,appId:"SMcDFP1bN1jgb9Lo8JmtICHm-gzGzoHsz",appKey:"dH4nrUrt3V5XiJiI6Qyejnbi",placeholder:"",path:window.location.pathname,avatar:"monsterid",guest_info:["nick","mail","link"]});var chicken='<a href="#"><img src="https://image.uisdc.com/wp-content/uploads/2018/06/uisdc-chat-chicken.gif" class="checken"></a>';$("#comment-div").prepend(chicken)</script></div></div><script>var $bqinline=$("img[alt='bq-inline']");$bqinline.css({width:"2.3rem",height:"2.3rem",display:"inline","vertical-align":"text-bottom"})</script></div><div class="comments" id="comments"></div></div><aside id="sidebar" class="sidebar" onselectstart="return!1"><div class="sidebar-inner"><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">Contents</li><li class="sidebar-nav-overview" data-target="site-overview">Site Preview</li></ul><section class="site-overview sidebar-panel"><div class="sidebar-sticky sticky"><div itemscope itemtype="http://schema.org/Person"><div class="author__avatar"><img src="/images/blogImage.jpg" class="author__avatar" alt="MrBird" itemprop="image"></div><div class="author__content"><h3 class="author__name" itemprop="name">MrBird's Blog</h3><p class="author__bio" itemprop="description">A simple blog, code repository, just keep blogging</p></div><div class="author__urls-wrapper"><button class="btn btn--inverse">Follow</button><ul class="author__urls social-icons"><li><a href="http://map.baidu.com/?newmap=1&s=s%26wd%3D%E7%A6%8F%E5%B7%9E%E5%B8%82%26c%3D300&from=alamap&tpl=mapcity" target="_blank" itemprop="url" class="ignore-href"><i class="fa fa-fw fa-map-marker" aria-hidden="true"></i>&nbsp;&nbsp;FuZhou,CN</a></li><li><a href="https://love.mrbird.cc" target="_blank" itemprop="url" class="ignore-href"><i class="fa fa-fw fa-diamond" aria-hidden="true"></i>&nbsp;&nbsp;Love</a></li><li><a href="https://cloud.mrbird.cn" target="_blank" itemprop="url" class="ignore-href"><i class="fa fa-fw fa-chain" aria-hidden="true"></i>&nbsp;&nbsp;FEBS</a></li><li><a href="/atom.xml" target="_blank" itemprop="url" class="ignore-href"><i class="fa fa-fw fa-rss" aria-hidden="true"></i>&nbsp;&nbsp;RSS</a></li><li><a href="https://gitee.com/mrbirdd" target="_blank" itemprop="sameAs" class="ignore-href"><i class="fa fa-fw fa-codepen" aria-hidden="true"></i>&nbsp;&nbsp;Gitee</a></li><li><a href="https://github.com/wuyouzhuguli" target="_blank" itemprop="sameAs" class="ignore-href"><i class="fa fa-fw fa-github-alt" aria-hidden="true"></i>&nbsp;&nbsp;GitHub</a></li><li><a href="javascript:;" class="popup-trigger"><i class="fa fa-fw fa-search" aria-hidden="true"></i>&nbsp;&nbsp;Search</a></li></ul></div></div></div><script>var $urls=$(".author__urls").find("a");$urls.each(function(){var o=$(this);o.mouseenter(function(){o.css({color:"#414547"})}),o.mouseleave(function(){o.css({color:""})})})</script></section><section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active"><div class="post-toc"><div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#association"><span class="nav-number">1.</span> <span class="nav-text">association</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#collection"><span class="nav-number">2.</span> <span class="nav-text">collection</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#discriminator"><span class="nav-number">3.</span> <span class="nav-text">discriminator</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#延迟加载"><span class="nav-number">4.</span> <span class="nav-text">延迟加载</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#另外一种级联"><span class="nav-number">5.</span> <span class="nav-text">另外一种级联</span></a></li></ol></div></div></section></div></aside></div></main><footer id="footer" class="footer" onselectstart="return!1"><div class="footer-inner"><div class="copyright">&copy; 2016 - <span itemprop="copyrightYear">2019</span>&nbsp;&nbsp; <span class="author" itemprop="copyrightHolder">MrBird</span>&nbsp;&nbsp;|<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>&nbsp;&nbsp;UV&nbsp;<span class="busuanzi-value" id="busuanzi_value_site_uv" style="cursor:pointer" title="统计开始时间：2019年7月5日"></span> &nbsp;&nbsp;PV&nbsp;<span class="busuanzi-value" id="busuanzi_value_site_pv" style="cursor:pointer" title="统计开始时间：2019年7月5日"></span></div></div></footer><div class="back-to-top"><span style="font-family:'Source Sans Pro','Helvetica Neue',Arial,sans-serif;font-size:1.2em;font-weight:600">TOP</span></div></div><script type="text/javascript">"[object Function]"!==Object.prototype.toString.call(window.Promise)&&(window.Promise=null)</script><script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script><script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script><script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script><script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script><script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script><script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script><script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script><script type="text/javascript">function proceedsearch(){$("body").append('<div class="search-popup-overlay local-search-pop-overlay"></div>').css("overflow","hidden"),$(".search-popup-overlay").click(onPopupClose),$(".popup").toggle();var t=$("#local-search-input");t.attr("autocapitalize","none"),t.attr("autocorrect","off"),t.focus()}var isfetched=!1,isXml=!0,search_path="search.xml";0===search_path.length?search_path="search.xml":search_path.endsWith("json")&&(isXml=!1);var path="/"+search_path,onPopupClose=function(t){$(".popup").hide(),$("#local-search-input").val(""),$(".search-result-list").remove(),$("#no-result").remove(),$(".local-search-pop-overlay").remove(),$("body").css("overflow","")},searchFunc=function(t,e,o){"use strict";$("body").append('<div class="search-popup-overlay local-search-pop-overlay"><div id="search-loading-icon"><i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i></div></div>').css("overflow","hidden"),$("#search-loading-icon").css("margin","20% auto 0 auto").css("text-align","center"),$.ajax({url:t,dataType:isXml?"xml":"json",async:!0,success:function(t){isfetched=!0,$(".popup").detach().appendTo(".header-inner");var n=isXml?$("entry",t).map(function(){return{title:$("title",this).text(),content:$("content",this).text(),url:$("url",this).text()}}).get():t,r=document.getElementById(e),s=document.getElementById(o),a=function(){var t=r.value.trim().toLowerCase(),e=t.split(/[\s\-]+/);e.length>1&&e.push(t);var o=[];if(t.length>0&&n.forEach(function(n){function r(e,o,n,r){for(var s=r[r.length-1],a=s.position,i=s.word,l=[],h=0;a+i.length<=n&&0!=r.length;){i===t&&h++,l.push({position:a,length:i.length});var p=a+i.length;for(r.pop();0!=r.length&&(s=r[r.length-1],a=s.position,i=s.word,p>a);)r.pop()}return c+=h,{hits:l,start:o,end:n,searchTextCount:h}}function s(t,e){var o="",n=e.start;return e.hits.forEach(function(e){o+=t.substring(n,e.position);var r=e.position+e.length;o+='<b class="search-keyword">'+t.substring(e.position,r)+"</b>",n=r}),o+=t.substring(n,e.end)}var a=!1,i=0,c=0,l=n.title.trim(),h=l.toLowerCase(),p=n.content.trim().replace(/<[^>]+>/g,""),u=p.toLowerCase(),f=decodeURIComponent(n.url),d=[],g=[];if(""!=l&&(e.forEach(function(t){function e(t,e,o){var n=t.length;if(0===n)return[];var r=0,s=[],a=[];for(o||(e=e.toLowerCase(),t=t.toLowerCase());(s=e.indexOf(t,r))>-1;)a.push({position:s,word:t}),r=s+n;return a}d=d.concat(e(t,h,!1)),g=g.concat(e(t,u,!1))}),(d.length>0||g.length>0)&&(a=!0,i=d.length+g.length)),a){[d,g].forEach(function(t){t.sort(function(t,e){return e.position!==t.position?e.position-t.position:t.word.length-e.word.length})});var v=[];0!=d.length&&v.push(r(l,0,l.length,d));for(var C=[];0!=g.length;){var $=g[g.length-1],m=$.position,x=$.word,w=m-20,y=m+80;w<0&&(w=0),y<m+x.length&&(y=m+x.length),y>p.length&&(y=p.length),C.push(r(p,w,y,g))}C.sort(function(t,e){return t.searchTextCount!==e.searchTextCount?e.searchTextCount-t.searchTextCount:t.hits.length!==e.hits.length?e.hits.length-t.hits.length:t.start-e.start});var T=parseInt("1");T>=0&&(C=C.slice(0,T));var b="";b+=0!=v.length?"<li><a href='"+f+"' class='search-result-title'>"+s(l,v[0])+"</a>":"<li><a href='"+f+"' class='search-result-title'>"+l+"</a>",C.forEach(function(t){b+="<a href='"+f+'\'><p class="search-result">'+s(p,t)+"...</p></a>"}),b+="</li>",o.push({item:b,searchTextCount:c,hitCount:i,id:o.length})}}),1===e.length&&""===e[0])s.innerHTML='<div id="no-result"><i class="fa fa-search fa-5x" /></div>';else if(0===o.length)s.innerHTML='<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>';else{o.sort(function(t,e){return t.searchTextCount!==e.searchTextCount?e.searchTextCount-t.searchTextCount:t.hitCount!==e.hitCount?e.hitCount-t.hitCount:e.id-t.id});var a='<ul class="search-result-list">';o.forEach(function(t){a+=t.item}),a+="</ul>",s.innerHTML=a}};r.addEventListener("input",a),$(".local-search-pop-overlay").remove(),$("body").css("overflow",""),proceedsearch()}})};$(".popup-trigger").click(function(t){t.stopPropagation(),isfetched===!1?searchFunc(path,"local-search-input","local-search-result"):proceedsearch()}),$(".popup-btn-close").click(onPopupClose),$(".popup").click(function(t){t.stopPropagation()}),$(document).on("keyup",function(t){var e=27===t.which&&$(".search-popup").is(":visible");e&&onPopupClose()})</script></body><script>$(function(){$("a").not(".nav-link,.cloud-tie-join-count,.ignore-href,.jstree-anchor").addClass("animsition-link")});var burst1=new mojs.Burst({left:0,top:0,radius:{5:40},children:{shape:"circle",fill:["red","cyan","orange"],fillOpacity:.8,radiusX:3.5,radiusY:3.5}});document.addEventListener("click",function(a){null==a.target.href&&"footer"!=a.target.className&&"copyright"!=a.target.className&&"author__urls social-icons"!=a.target.className&&"author__avatar"!=a.target.className&&"sidebar sidebar-active"!=a.target.className&&burst1.tune({x:a.pageX,y:a.pageY}).generate().replay()})</script><script type="text/javascript" src="/js/message.js"></script></html><!-- rebuild by neat -->